package com.ruiboyun.liveapp.presenter.impl;

import com.alibaba.fastjson.JSON;
import com.ruiboyun.liveapp.base.Url;
import com.ruiboyun.liveapp.bean.ChannelEntity;
import com.ruiboyun.liveapp.http.OkHttpManager;
import com.ruiboyun.liveapp.http.OnResponseListener;
import com.ruiboyun.liveapp.presenter.ChannelPresenter;
import com.ruiboyun.liveapp.util.tool.EditorShare;
import com.ruiboyun.liveapp.util.tool.Loger;
import com.ruiboyun.liveapp.view.BaseView;
import com.ruiboyun.liveapp.view.ChannelView;

/**
 * Created by wushiqian on 2017/9/17.
 */

public class ChannelPresenterImpl extends BasePresenterImpl implements ChannelPresenter {
    public ChannelPresenterImpl(BaseView baseView) {
        super(baseView);
    }

    @Override
    public void getChannel() {
        final String string = EditorShare.getString(Url.PORT);
        OkHttpManager.getInstance().getChannels(string, new OnResponseListener<ChannelEntity>() {
            @Override
            public void Success(ChannelEntity channelEntity) {
                getView().getChannelSucces(channelEntity);
                Loger.e(string+"channel"+JSON.toJSONString(channelEntity));
            }

            @Override
            public void onFailed(int errorCode) {
                Loger.e(errorCode+"channel");
                getView().showTips("系统异常");
            }

            @Override
            public void onException(String msg) {
                Loger.e(msg+"channel");
                getView().showTips(msg);
            }
        });
    }

    @Override
    public ChannelView getView() {
        return (ChannelView) baseView;
    }
}
